package arkanoid.components.ball;

import java.awt.Color;

import javax.swing.Timer;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.events.constants.Key;

import arkanoid.components.Palette;

public class DisattachedStickyBall extends DisattachedBall {
	
	public DisattachedStickyBall(int duration, Ball ball) {
		Timer timer = new Timer(1000, new TimerListener(duration, ball));
		timer.start();
		ball.changeColor(Color.getHSBColor(0.26f, 1.0f, 0.8f));
	}
	
	@Override
	public void update(Ball ball, DeltaState deltaState) {
		Palette palette = ball.getScene().getPalette();
		if (this.ballCollidesAgainstPalette(ball, palette)) {
			ball.move(palette.getX() + palette.getWidth() / 2 - ball.getX(), 0);
			if (deltaState.isKeyPressed(Key.Z)) {
				ball.setY(palette.getY() - ball.getDiameter());
				ball.setVersorJ(-ball.getVersorJ());
				super.update(ball, deltaState);
			}
		}
		else {
			super.update(ball, deltaState);
		}
	}
}
